package com.wing.res.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.common.utils.PageResult;
import com.wing.res.model.request.PaiBanInfo;
import com.wing.system.model.response.DingTalkAttendanceVO;
import com.wing.system.service.DingTalkAttendanceService;
import com.wing.web.annotation.RequestObjectFieldIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 *
 * @author
 */
@Validated
@Api(value = "Admin-钉钉考勤管理第三方", tags = "#/res/dingTalkAttendance/dingTalkAttendanceList")
@RestController("DingTalkAttendanceController")
@RequestMapping("res/admin/dingTalkAttendance")
@RequiredArgsConstructor
public class DingTalkAttendanceController {

    @Autowired
    DingTalkAttendanceService dingTalkAttendanceService;

    @ApiOperation(value = "手动同步钉钉排班-考勤相关数据", notes = "添加")
    @RequestObjectFieldIgnore({"id", "createTime", "remark"})
    @PostMapping("/syncDingAttendanceToSystem")
    public void syncDingAttendanceToSystem(@RequestBody PaiBanInfo paiBanInfo) throws Exception {
        if(StringUtils.isEmpty(paiBanInfo.getStartTime())){
            return;
        }
        if(StringUtils.isEmpty(paiBanInfo.getEndTime())){
            return;
        }
        dingTalkAttendanceService.syncDingAttendanceToSystem(paiBanInfo.getStartTime(),paiBanInfo.getEndTime());
    }


    @ApiOperation(value = "手动同步钉钉考勤班次相关数据", notes = "添加")
    @RequestObjectFieldIgnore({"id", "createTime", "remark"})
    @GetMapping("/syncDingAttendanceBanCiSystem")
    public void syncDingAttendanceBanCiSystem() throws Exception {
        dingTalkAttendanceService.syncDingAttendanceBanCiSystem();
    }




    @ApiOperation(value = "查询员工考勤数据列表", notes = "搜索-任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
    })
    @GetMapping("/selDingTalkAttendanceInfo")
    public PageResult<DingTalkAttendanceVO> selDingTalkAttendanceInfo(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "asc") String order
            ,String paiBanMouth
            ,String groupId
            /*
            ,String factoryName
            ,String purchaseTissue
            ,String materialCode
            */
    ) {
        Page<DingTalkAttendanceVO> pg = new Page<>(page, limit);
        HashMap map = new HashMap();
      /*  map.put("purchaseTissue", purchaseTissue);
        map.put("factoryName", factoryName);
        map.put("materialCode", materialCode);
       */
        map.put("paiBanMouth", paiBanMouth);
        map.put("groupId", groupId);
        Page<DingTalkAttendanceVO> list = dingTalkAttendanceService.selDingTalkAttendanceInfo(pg, map);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }




    @ApiOperation(value = "查询员工考勤排班数据列表", notes = "搜索-任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
    })
    @GetMapping("/list")
    public PageResult<DingTalkAttendanceVO> selDingTalkAttendancePaiBanInfo(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "asc") String order
            ,String startTime
            ,String endTime
            ,String groupName
            /*
            ,String factoryName
            ,String purchaseTissue
            ,String materialCode
            */
    ) {
        Page<DingTalkAttendanceVO> pg = new Page<>(page, limit);
        HashMap map = new HashMap();
      /*  map.put("purchaseTissue", purchaseTissue);
        map.put("factoryName", factoryName);
        map.put("materialCode", materialCode);
       */
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        map.put("groupName", groupName);
        Page<DingTalkAttendanceVO> list = dingTalkAttendanceService.selDingTalkAttendancePaiBanInfo(pg, map);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }





}
